package com.accenture.fd.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.accenture.fd.entity.ItemControlEntity;

	@Mapper
	public interface ItemControlDao {

		@Delete("delete from TB00015 where screen_id = #{screenId}")
		void delItemControlByScreenId(@Param("screenId") String screenId);
		
		@Select("select screen_id from TB00015 where screen_id = #{screenId}")
		@Results({ @Result(property = "screenId", column = "screen_id"), })
		List<String> selectItemControlByScreenId(@Param("screenId") String screenId);
		
		     @Insert("insert into TB00015 value (" + 
		    		 "#{item.designTypeId},"+
		    		 "#{item.screenId},"+
		    		 "#{item.section},"+
		    		 "#{item.screenItemName},"+
		    		 "#{item.controlLevel1},"+
		    		 "#{item.controlLevel2},"+
		    		 "#{item.controlSection},"+
		    		 "#{item.control})")
		     void save(@Param("item")ItemControlEntity item);
		     
		     @Insert({
		    	 "<script>",
		    	 "insert into TB00015 value ",
		    	 "<foreach collection='controlList' item='item' index='index' separator=','>",
		    	 "("+ 
	    			 "#{item.designTypeId},"+
		    		 "#{item.screenId},"+
		    		 "#{item.section},"+
		    		 "#{item.screenItemName},"+
		    		 "#{item.controlLevel1},"+
		    		 "#{item.controlLevel2},"+
		    		 "#{item.controlSection},"+
		    		 "#{item.control})"+
		    	 "</foreach>",
		    	 "</script>"
		    	})
		     void saveAll(@Param(value="controlList") List<ItemControlEntity> controlList);
		     
		     @Select("select\r\n" +
			     		"  design_type_id,\r\n" +
			     		"  screen_id,\r\n" +
			     		"  section,\r\n" +
			     		"  screen_item_name,\r\n" +
			     		"  control_level_1,\r\n" +
			     		"  control_level_2,\r\n" +
			     		"  control_section,\r\n" +
			     		"  control \r\n" +
			     		"  from TB00015\r\n" +
			     		"  where design_type_id=#{designTypeId} \r\n" +
			     		"  and screen_id=#{screenId}\r\n" +
			     		"  and section=#{section} and control='〇' \r\n" )
			@Results({ 
				    @Result(property = "designTypeId", column = "design_type_id"),
					@Result(property = "screenId", column = "screen_id"),
					@Result(property = "section", column = "section"),
					@Result(property = "screenItemName", column = "screen_item_name"), 
				    @Result(property = "controlLevel1", column = "control_level_1"),
					@Result(property = "controlLevel2", column = "control_level_2"),
					@Result(property = "controlSection", column = "control_section"),
					@Result(property = "control", column = "control")
					})
		     List<ItemControlEntity> selItemControl(@Param("designTypeId") String designTypeId,
					@Param("screenId") String screenId, @Param("section") int section);

	}
